<?php
namespace app\api\controller;
use app\api\model\WxappPage;
//use app\api\model\Goods as GoodsModel;
use app\api\model\Shop as ShopModel;
//use app\api\model\Article as ArticleModel;

/**
 * 首页控制器
 */
class Index extends Controller
{
    /**
     * 首页diy数据
     */
    public function page()
    {
        // 页面元素
        $wxappPage = WxappPage::diyPage();
        $items = $wxappPage['page_data']['array']['items'];
		for($n=0;$n<sizeof($items);$n++){
			/*
			if($items[$n]['type']=='article'){//文章组
				$list = ArticleModel::getAll($items[$n]['params']['auto']['category'],$items[$n]['params']['auto']['showNum'],10);
				$items[$n]['data'] = $list;
			}
			if($items[$n]['type']=='special'){//头条快报
				$list = ArticleModel::getAll($items[$n]['params']['auto']['category'],$items[$n]['params']['auto']['showNum']);
				$items[$n]['data'] = $list;
			}
			*/
			if($items[$n]['type']=='shop' AND $items[$n]['params']['source']=='auto'){//线下门店
				$list = ShopModel::getAll($items[$n]['params']['auto']['showNum']);
				for($m=0;$m<sizeof($list);$m++){
					$list[$m]['logo_image']=$list[$m]['logo']['file_path'];
				}
				$items[$n]['data'] = $list;
			}
			/*
			if($items[$n]['type']=='goods' AND $items[$n]['params']['source']=='auto'){//商品组自动获取
				$category_id = null;
				$limit = $items[$n]['params']['auto']['showNum'];
				$sortType = $items[$n]['params']['auto']['goodsSort'];
				if($items[$n]['params']['auto']['category']>0){
					$category_id = $items[$n]['params']['auto']['category'];
				}
				$model = new GoodsModel;
				$list = $model->getApiList(10, $category_id, $search=null, $sortType, $sortPrice = false,$limit);
				$news = [];
				for($m=0;$m<sizeof($list);$m++){
					$news[$m] = [
						'goods_id' => $list[$m]['goods_id'],
						'goods_name' => $list[$m]['goods_name'],
						'image' => $list[$m]['thumbnail'],
						'goods_price' => $list[$m]['spec'][0]['goods_price'],
						'line_price' => $list[$m]['spec'][0]['line_price'],
						'selling_point' => $list[$m]['selling_point'],
						'goods_sales' => $list[$m]['goods_sales']
					];
				}
				$items[$n]['data'] = $news;
			}
			*/
		}
        return $this->renderSuccess(compact('items'));
    }

}
